package com.alibaba.dubbo.rpc.protocol.dubbo;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import com.alibaba.dubbo.common.HeaderProvider2;

@java.lang.Deprecated
public class ResponseResult implements HeaderProvider2, Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Object result;
	private Map<String, String> headers;
	
	public ResponseResult(Map<String, String> headers){
		headers = new HashMap<String, String>(headers);
	}
	
	public ResponseResult(Object value){
		this.result = value;
		headers = new HashMap<String, String>();
	}
	
	public ResponseResult(){
		headers = new HashMap<String, String>();
	}

	
	public Object getValue() {
		return result;
	}

	public void setValue(Object value) {
		this.result = value;
	}

	
	@Override
	public Map<String, String> getHeaders() {
		return this.headers;
	}
	
	@Override
	public void setHeaders(Map<String, String> values) {
		this.headers.clear();
		if(values != null) this.headers.putAll(values);
	}

	@Override
	public String getHeader(String key) {
		if(this.headers == null) return null;
		return this.headers.get(key);
	}

	@Override
	public String getHeader(String key, String defaultValue) {
		String value = this.getHeader(key);
		if(value == null || value.length() == 0) return defaultValue;
		return value;
	}

	@Override
	public String removeHeader(String key) {
		if(this.headers == null) return null;
		return this.headers.remove(key);
	}
	
	@Override
	public void removeHeaders() {
		if(this.headers != null){
			this.headers.clear();
		}
	}

	@Override
	public void setHeader(String key, String value) {
		if(this.headers != null) this.headers = new HashMap<String, String>();
		this.headers.put(key, value);
	}

	@Override
	public boolean containsHeader(String key) {
		if(this.headers == null) return false;
		return this.headers.containsKey(key);
	}

}
